Skip to content

add the ability to co_await sender adaptor closure objects#1601

Merged
ericniebler merged 7 commits intoNVIDIA:mainfrom
ericniebler:co-await-sender-adaptor-closures
Aug 4, 2025
Merged

add the ability to co_await sender adaptor closure objects#1601
ericniebler merged 7 commits intoNVIDIA:mainfrom
ericniebler:co-await-sender-adaptor-closures

Conversation

@ericniebler
Copy link
Copy Markdown
Collaborator

within a coroutine returning exec::basic_task<Context>, it is now possible to co_await a sender adaptor closure object. it is used to adapt a just()-like sender that provides the coroutine's scheduler type as its completion scheduler.

the result is that algorithm customizations can be found. for example, given:

  struct test_domain {
    template <sender_expr_for<then_t> _Sender>
    static constexpr auto transform_sender(_Sender&& __sndr) noexcept {
      return just("goodbye"s);
    }
  };

  struct test_task_context {
    constexpr test_task_context(auto&&...) noexcept {
    }

    template <class _ThisPromise>
    using promise_context_t = test_task_context;

    template <class, class>
    using awaiter_context_t = test_task_context;

    static constexpr auto query(get_scheduler_t) noexcept {
      return basic_inline_scheduler<test_domain>{};
    }
  };

  template <class T>
  using test_task = exec::basic_task<T, test_task_context>;

in a coroutine returning a test_task<T> object, it is possible to:

auto msg = co_await stdexec::then([] { return "hello"s; });
assert(msg == "goodbye"s);

and that will find test_domain::transform_sender that transforms the then sender into a just("goodbye"s) sender.

this PR also reworks support for static constexpr query member functions.

@ericniebler ericniebler merged commit 3eb5736 into NVIDIA:main Aug 4, 2025
18 checks passed
@ericniebler ericniebler deleted the co-await-sender-adaptor-closures branch August 4, 2025 05:44
gamecentric pushed a commit to gamecentric/stdexec that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant